unit uDataSource;

{$mode Delphi}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,
  StdCtrls, Spin, Buttons, Menus, laz.VirtualTrees, ufmSqlserversourcset;

type

  PTreeData = ^TTreeData;

  TTreeData = record
    FmSet: TObject;

  end;

  { TFmDataSource }

  TFmDataSource = class(TForm)
    Button1: TButton;
    ConnectTree: TLazVirtualStringTree;
    MenuSqlserver: TMenuItem;
    MenuMysql: TMenuItem;
    PageControlSource: TPageControl;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    PopupDrive: TPopupMenu;
    SpeedButton1: TSpeedButton;
    Timer1: TTimer;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MenuSqlserverClick(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    tabsList: TList;
  private
    procedure RefreshSessions(ParentNode: PVirtualNode);
    procedure SetMainTab(Page: TTabSheet);
    function CreateTab(): TFmSQLServerSet;
  public

  end;

var
  FmDataSource: TFmDataSource;

implementation

{$R *.lfm}

uses appTool;

  { TFmDataSource }

procedure TFmDataSource.MenuSqlserverClick(Sender: TObject);
var
  lvitem: TListItem;
  ParentNode, NewNode: PVirtualNode;
  pData: PTreeData;
begin
  //lvitem := ListViewConnect.Items.Add;
  //lvitem.ImageIndex:=0;
  //lvitem.Caption:='@localhost';
  new(pData);
  pData.FmSet := CreateTab();
  NewNode := ConnectTree.AddChild(nil, pData);  //PConnectionParameters(NewSess)
  // Select it

  //@localhost
  SelectNode(ConnectTree, NewNode);
end;

procedure TFmDataSource.Panel1Click(Sender: TObject);
begin

end;

procedure TFmDataSource.SpeedButton1Click(Sender: TObject);
begin
  SetMainTab(TTabSheet(tabsList[0]));
end;

procedure TFmDataSource.RefreshSessions(ParentNode: PVirtualNode);
begin

end;

procedure TFmDataSource.Button1Click(Sender: TObject);
begin
end;

procedure TFmDataSource.FormCreate(Sender: TObject);
begin
  tabsList := TList.Create;
end;

procedure TFmDataSource.SetMainTab(Page: TTabSheet);
begin
  // Safely switch main tab
  if (Page <> nil) {and (not FTreeRefreshInProgress)} then
  begin
    PageControlSource.ActivePage := Page;
    //PageControlSource.OnChange(Page);
  end;
end;

function TFmDataSource.CreateTab(): TFmSQLServerSet;
var
  lvitem: TListItem;
  fmSourceset: TFmSQLServerSet;
  lvtabsheet: TTabSheet;
begin
  //ListViewConnect.Items.Item[ListViewConnect.ItemIndex];
  lvtabsheet := TTabSheet.Create(PageControlSource);
  tabsList.Add(lvtabsheet);
  lvtabsheet.PageControl := PageControlSource;

  fmSourceset := TFmSQLServerSet.Create(lvtabsheet);
  //fmSourceset.TabSheet.Name := tabQuery.Name + i.ToString;
  //fmSourceset.TabSheet.ImageIndex := tabQuery.ImageIndex;
  fmSourceset.Parent := lvtabsheet;
  fmSourceset.Align := alClient;
  fmSourceset.TabSheet := lvtabsheet;
  lvtabsheet.TabVisible:= false;
  fmSourceset.Show;
  //for i:= 0 to tabsList do
  //begin
  //  TTabSheet(tabsList[i]).TabVisible:=false;
  //end;
  SetMainTab(lvtabsheet);
  Result := fmSourceset;
end;


end.
